//==========================================================================
// Copyright (c) 2000-2006,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#if !defined(__CAMPLUS_H_)
#define __CAMPLUS_H_

#include <zenr_api.h>

#define nu_CameraInit                zapi_Camera->Init
#define nu_CameraDeinit              zapi_Camera->Deinit
#define nu_CameraStart               zapi_Camera->Start
#define nu_CameraStop                zapi_Camera->Stop
#define nu_CameraAck                 zapi_Camera->Ack
#define nu_CameraShowFrame           zapi_Camera->ShowFrame
#define nu_CameraSetFlashLED         zapi_Camera->SetFlashLED
#define nu_CameraSetBrightness       zapi_Camera->SetBrightness
#define nu_CameraSetWhiteBalance     zapi_Camera->SetWhiteBalance
#define nu_CameraSetColoreffects     zapi_Camera->SetColoreffects
#define nu_CameraSetResolution       zapi_Camera->SetResolution
#define nu_CameraSetContrast         zapi_Camera->SetContrast
#define nu_CameraSetZoom             zapi_Camera->SetZoom
#define nu_CameraSetScenemode        zapi_Camera->SetScenemode


#define CAMERA_DATA_BYTES     2

typedef struct {
    BYTE *pY;
    BYTE *pCb;
    BYTE *pCr;
} YCbCrBufferInfo;

typedef struct tagRECT {
    long left;
    long top;
    long right;
    long bottom;
} RECT, *PRECT;

#define PREVIEW_WIDTH   240
#define PREVIEW_HEIGHT  320

#define PHOTO_MODE 0
#define VIDEO_MODE 1

#include "camera.h"
#include "camvideo.h"
#include "camsnapshot.h"

typedef struct {
    int m_imode;
    int m_iPhotoResolution;//OK
    int m_iVideoResolution;//OK
    int m_iPhotoZoom;//Must be supported
    int m_iBrightness;//OK
    int m_iWhiteBalance;//OK
    int m_iColorMode;//OK
    int m_iSceneMode;//Must be supported
    int m_iContinuousSnaps;//Must be supported
    int m_iFrameRate;//dummy
    int m_iContrast;//dummy
    int m_iSharpness;//dummy
    int m_iDirection;//dummy
    int m_iFlash;//dummy
    int m_iISO;//dummy
    int m_iExposureCompensation;//dummy
} CamFormat;


class CameraDriver
{
public:

    ECode CamDrv_Initialize();

    void  CamDrv_Quit();

    ECode CamDrv_GetSnapshotFrames(Camera_Photo *pPhoto);

    ECode CamDrv_BeginPreview(IEvent ** ppOutEvent);

    ECode CamDrv_GetPreviewFrame(Camera_ImageFrame *pFrame);

    ECode CamDrv_StopPreview();

    void  CamDrv_ReleaseFrames();

    ECode CamDrv_SetAppFormat(unsigned int nID, int wParam, int lParam);

    ECode CamDrv_GetAppFormat(unsigned int nID, int *pwParam, int *plParam);

    ECode CamDrv_SetCamMode(int iMode);

    ECode CamDrv_BeginVideoRecord(IEvent ** ppOutEvent);

    ECode CamDrv_StopVideoRecord();

    ECode CamDrv_GetVideoFrame(Camera_ImageFrame* pFrame);

public:
    CCamVideo m_Preview;
    CCamVideo *m_pVideo;
    CCamSnapshot *m_pSnapshot;
    CamFormat m_Format;
};


EXTERN CameraDriver g_CameraDriver;

EXTERN uint_t GetOrder(int iWidth, int iHeight);
EXTERN void TurnYCbCrToRGB565(Uint16 *pYCbCr, Uint16 *pRGB565, int iWidth, int iHeight);
EXTERN void V2H(void *pV, void *pH, int iWidth, int iHeight, int count);
EXTERN void TurnYUV_VToRGB565_H(Uint16 *pYUVSrc, Uint16 *pRGB565Des, int iSrcFrameWidth, int iSrcFrameHeight);
EXTERN void ResolutionOfVideo(int iResolution,
                      int *pWidth,
                      int *pHeight);
EXTERN void ResolutionOfSnapshot(int iResolution,
                      int *pWidth,
                      int *pHeight);

extern void Nu_DmaBufFree(physaddr_t ptr, size_t size);
extern void *Nu_DmaBufAlloc(size_t size, Int32 bUserAccess);
#endif //__CAMPLUS_H_
